package com.itboye.jinpuyiyuan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.itboye.jinpuyiyuan.R;
import com.itboye.jinpuyiyuan.activity.home.hospitalserver.DailyListDetailActivity;
import com.itboye.jinpuyiyuan.bean.DailyInfoBean;
import com.itboye.jinpuyiyuan.bean.DayOrderBean;
import com.itboye.jinpuyiyuan.widget.MyListView;

import java.util.List;

public class DailyListDetailAdapter extends BaseAdapter {

    Context context;
    List<DailyInfoBean.Fee.FeeDetail> list;
    DailyOrderAdapter orderAdapter;

    public DailyListDetailAdapter(Context context, List<DailyInfoBean.Fee.FeeDetail> list){
        this.context=context;
        this.list=list;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        MyViewHolder myViewHolder;
        if (convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.item_dailylistdetai, null, false);
            myViewHolder=new MyViewHolder(convertView) ;
            convertView.setTag(myViewHolder);
        }else {
            myViewHolder= (MyViewHolder) convertView.getTag();
        }

           myViewHolder.categoryName.setText(list.get(position).getFee_name());
           myViewHolder.sumMoney.setText(list.get(position).getFee_money());
           if (list.get(position).getItem_detail()!=null){
               orderAdapter=new DailyOrderAdapter(context,list.get(position).getItem_detail());
               myViewHolder.itemLv.setAdapter(orderAdapter);
           }

        return convertView;
    }

    public void addData(List<DailyInfoBean.Fee.FeeDetail> list){

        this.list=list;
        notifyDataSetChanged();
    }

    class MyViewHolder{

        TextView categoryName; //西药费
        TextView sumMoney; //合计

        MyListView itemLv;

        public MyViewHolder(View itemView){
         categoryName=itemView.findViewById(R.id.categoryName);
         sumMoney=itemView.findViewById(R.id.sumMoney);
         itemLv=itemView.findViewById(R.id.itemLv);

        }
    }
}
